#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>

using namespace std;
// #define x first
// #define y second
const int N = 1e6 + 10;
typedef pair<int, int> PII;
PII order[N];
int n, m, T;
int score[N], last[N];
bool st[N];
int main(int argc, char const *argv[])
{
    scanf("%d%d%d", &n, &m, &T);
    for (int i = 0; i < m; i++)
        scanf("%d%d", &order[i].first, &order[i].second);
    sort(order, order + m);
    for (int i = 0; i < m;)
    {
        int j = i;
        while (j < m && order[i] == order[j])
            j++;
        i = j;
        int t = order[i].first, id = order[i].second, cnt = j - i;
        score[id] -= t - last[id] + 1;
        if (score[id] < 0)
            score[id] = 0;
        if (score[id] <= 3)
            st[id] = false;
        score[id] += cnt * 2;
        if (score[id] > 5)
            st[id] = true;
        last[id] = t;
    }
    for (int i = 1; i <= n; i++)
    {
        if (last[i] < T)
        {
            score[i] -= T - last[i];
            if (score[i] < 3)
                st[i] = false;
        }
    }
    int res;
    for (int i = 0; i < n; i++)
        res += st[i];
    cout << res << endl;
    return 0;
}
